package com.bocaizp.operation.controller.user;

import com.bocaizp.common.result.Result;
import com.bocaizp.operation.service.ChatService;
import com.bocaizp.pojo.VO.AddFriendVO;
import com.bocaizp.pojo.VO.FriendListVO;
import com.bocaizp.pojo.VO.OtherInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author : huang jie
 * Date : 2024/5/9 23:56
 **/
@RestController
@RequestMapping("/user")
@Slf4j
@CrossOrigin
public class ChatController {

	@Autowired
	private ChatService chatService;


	/**
	 * 获取好友列表
	 * @return
	 */
	@PostMapping("/chat/friend")
	public Result<List<FriendListVO>> getFriendList(){
		log.info("获取好友列表请求...");
		List<FriendListVO> friendListVOS = chatService.getfriend();
		return Result.success(friendListVOS);
	}

	/**
	 * 获取聊天历史
	 * @param id
	 * @return
	 */
	@GetMapping("/chat/info")
	public Result<OtherInfoVO> backHistory(String id){
		log.info("获取聊天历史...");
		OtherInfoVO otherInfoVO = chatService.getHistory(id);
		return Result.success(otherInfoVO);
	}

	/**
	 * 搜索好友
	 * @return
	 */
	@GetMapping("/chat/addfriend")
	public Result<List<AddFriendVO>> addFriendList(String username){
		log.info("添加好友请求...");
		List<AddFriendVO> addFriendVOS = chatService.addFriendList(username);
		return Result.success(addFriendVOS);
	}

	/**
	 * 添加好友
	 * @param id
	 * @return
	 */
	@GetMapping("/chat/buildchat")
	public Result buildChat(Long id){
		log.info("添加好友请求...对方id是：{}",id);
		chatService.build(id);
		return Result.success();
	}

	/**
	 * 删除好友
	 * @param id
	 * @return
	 */
	@GetMapping("/chat/delete")
	public Result deleteList(Long id){
		log.info("删除好友请求...");
		chatService.delete(id);
		return Result.success();
	}
}
